<template>
  <a-modal v-model="visible"   title="编辑污染大类"  @cancel='cancel' @ok='sure'>
      <a-table
        ref='table'
        size='middle'
        bordered
        :rowKey="record => record.polluteId"
        childrenColumnName='childrenColumnName'
        :columns='columns'
        :dataSource='dataSource'
        :pagination="false"
      >
        <span slot='action' slot-scope='text, record,index'>
          <a @click='handleEdit(record)'>编辑</a>
          <a-divider type='vertical' />
          <a @click='handleDel(record)'> 删除 </a>
        </span>
      </a-table>
    <EditPolluteSubclassModal ref="editPolluteSubclassModal" v-on:getPolluteList="getPolluteList"></EditPolluteSubclassModal>
  </a-modal>
</template>

<script>
import EpaSortService from '@/myService/EpaSortService'
import EditPolluteSubclassModal from '@views/epa/epa-statistics/Modal/EditPolluteSubclassModal'
export default {
  name: 'EditPolluteModal',
  components:{
    EditPolluteSubclassModal
  },
  data() {
    return {
      visible:false,
      dataSource: [],
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: (text, row, index) => 1 + index
        },
        {
          title: '污染大类',
          dataIndex: 'polluteName',
          align: 'center'
        },
        {
          title: '优先级',
          align: 'center',
          dataIndex: 'pollutePriority',

        },
        {
          title: '操作',
          key: 'action',
          align: 'center',
          scopedSlots: { customRender: 'action' }
        }
      ],
      data:{},
      loading:true
    }
  },
  created() {

  },
  methods:{
    handleDel(record){
      console.log(record)
      EpaSortService.deleteSortPolluteFalse({id:record.polluteId}).then((res)=>{
        this.getPolluteList()
      })
    },
    handleEdit(record){
      this.$refs.editPolluteSubclassModal.open(record)
    },
    cancel(){
      this.visible=false
      this.$emit('loading')
    },
    sure(){
      this.cancel()
    },
    open(){
      this.getPolluteList()
      this.visible=true
    },
    getPolluteList(){
      EpaSortService.getPolluteList().then((res)=>{
        this.dataSource=res.result
      })
    },
  }
}
</script>

<style scoped>

</style>